import unittest
import sys
import threading

sys.path.append('../../../Lib')

class Test(unittest.TestCase):
    def test_case1(self):
        """Just test case 1 <font color="red">##############################################################################</font>"""
        self.assertTrue(True, "Hello Failure.")
        for i in range(10000):
            pass
        print >> sys.stdout, '<font color="red">hello Pass1.</font>' + '=' * 300
        
    def test_case2(self):
        raise TypeError("Exception")
        
    def test_case3(self):
        self.assertTrue(False, "Hello Failure.")
        print >> sys.stderr, 'hello Pass3.'
    
    @unittest.skip("no reason")
    def test_case4(self):
        print("Skiped") 

def _run():
    runner = HTMLTestRunner(stream = fp, verbosity = 2)
    suite = unittest.TestSuite()
    suite.addTest(Test('test_case1'))
    runner.run(suite)

def runCases():
    with open('./test.html', 'wb') as fp:
        runner = HTMLTestRunner(stream = fp, verbosity = 2)
        suite = unittest.TestSuite()
        suite.addTest(Test('test_case1'))
        suite.addTest(Test('test_case2'))
        suite.addTest(Test('test_case3'))
        suite.addTest(Test('test_case4'))
        #threadPool = []
        #for i in range(0, 10):
        #    th = threading.Thread(target = _run)
        #    threadPool.append(th)
        #for th in threadPool:
        #    th.start()
        #for th in threadPool:
        #    th.join()
        runner.run(suite)
        #runner.runInThreads(suite, 3)


def redirectorUT():
    save_out = sys.stdout
    save_err = sys.stderr
    
    redirector = OutputRedirector()
    sys.stdout = redirector
    sys.stderr = redirector
    
    print >> sys.stdout, "Hello"
    print >> sys.stderr, "There"
    
    sys.stdout = save_out
    sys.stderr = save_err
    
    string = redirector.getvalue()
    print >> sys.__stderr__, string
    #print >> sys.__stderr__, string

if __name__ == '__main__':
    runCases()
    #redirectorUT()
    